<template>
  <div class="today">
    <div class="classify">
      <div>
        <span>分类</span>
        <div class="classify_item">
          <a
            :class="classifyId == 0 ? 'active' : ''"
            @click="checkClassify(0)"
          >全部</a>
          <a
          
            v-for="(item,index) in classify"
            :key="index"
            :class="classifyId == item.id ? 'active' : ''"
            @click="checkClassify(item)"
          >{{ item.cName }}</a>
        </div>
      </div>
    </div>
    <div class="classify">
      <div>
        <span> 地区</span>
        <div class="classify_item">
          <a
            :class="classifyareId == 0 ? 'active' : ''"
            @click="ArecheckClassify(0)"
          >全部</a>
          <a
            v-for="item in classifyare"
            :key="item.id"
            :class="classifyareId == item.id ? 'active' : ''"
            @click="ArecheckClassify(item)"
          >{{ item.cName }}</a>
        </div>
      </div>
    </div>
    <div class="sort">
      <div class="sortList">
        <a>排序:</a>
        <a
          v-for="item in areaData"
          :key="item.id"
          :class="item.isSelected ? 'active' : ''"
          @click="checkArea(item)"
        >{{ item.title }}</a>
      </div>
      <div class="search">
        <input
          v-model="keywords"
          type="text"
          placeholder="搜索你想要的商品"
          @keyup.13="searchThis"
        >
        <img
          src="../../assets/img/SS@2x.png"
          alt=""
          @click="searchThis"
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Classify",
  data() {
    return {
      classIfyData: [],
      areaData: [
        {
          title: "默认",
          isSelected: true,
          id: 0,
          value: "iOrder",
        },
        {
          title: "价格",
          isSelected: false,
          id: 1,
          value: "fSalePrice",
        },
        {
          title: "上架",
          isSelected: false,
          id: 2,
          value: "sj",
        },
        {
          title: "时间",
          isSelected: false,
          id: 3,
          value: "shijian",
        }
      ],
      classifyId: "",
      classifyare: [{
        cName: "香港",
        id:11
      },{
        cName: "澳门",
        id:22
      },{
        cName: "台湾",
        id:33
      },{
        cName: "日韩",
        id:44
      },{
        cName: "欧洲",
        id:55
      },{
        cName: "美洲",
        id:66
      }],
      classifyareId: '',
      areaId: "",
      classify: [],
      page: 1,
      keywords: "",
    };
  },
  mounted() {
    this.getData(this.$route.query.id);
  },

  methods: {
    // 获取分类
    getData(shop_id) {
      let data = {
        shop_id: shop_id
      }
      this.$api.commit.ShopCateGory(data).then((res) => {
        if (res.code == 1) {
          console.log('获取分类', res.data)
          this.classify = res.data;
        }
      });
    },
    checkClassify(checkClassify) {
       if (checkClassify) {
        this.classifyId = checkClassify.id;
      } else {
        this.classifyId = "";
      }
      this.$emit("getList", this.classifyId, this.cName);
    },
    ArecheckClassify(ArecheckClassify){
      if (ArecheckClassify) {
        this.classifyareId = ArecheckClassify.id;
      } else {
        this.classifyareId = "";
      }

      this.$emit("getList", this.classifyId);
    },
    checkArea(item) {
      this.areaData.forEach((items) => {
        items.isSelected = false;
        if (items.id == item.id) {
          this.areaId = item.value;
          this.$set(items, "isSelected", true);
        }
      });
      this.$emit("seletedType", this.areaId);
    },
    searchThis() {
      this.$emit("getList", this.classifyId, this.keywords);
    },
  },
};
</script>

<style scoped lang="scss">
.today {
  padding: 0 16.19rem;
  margin: 2.19rem 0;
  display: flex;
  flex-direction: column;

  .classify {
    background-color: #fff;
    padding: 1.18rem 1.68rem;
    border-bottom: 1px solid #e9e9e9;

    > div {
      align-items: center;
      display: flex;
      flex-direction: row;

      > span {
        width: 4rem;
        height: 4rem;
        background: rgba(13, 13, 13, 1);
        border-radius: 50%;
        font-size: 1rem;
        font-family: Microsoft YaHei;
        font-weight: 400;
        display: block;
        text-align: center;
        line-height: 4rem;
        color: rgba(255, 255, 255, 1);
        margin-right: 2rem;
      }

      > .classify_item {
        a {
          color: #666666;
          font-size: 1rem;
          margin-right: 2rem;
          line-height: 1.5rem;
          cursor: pointer;

          &.active {
            color: #08c19d;
          }
        }
      }
    }
  }

  :-webkit-input-placeholder {
    /* WebKit browsers */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  :-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #acacac;
    font-size: 0.88rem;
  }

  .sort {
    padding: 1.5rem 2rem;
    background: #fff;
    font-size: 1rem;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;

    .sortList {
      a {
        cursor: pointer;
        padding: 0 1rem;

        &.active {
          color: #08c19d;
        }
      }
    }

    .search {
      float: right;
      width: 20.94rem;
      height: 2rem;
      border-bottom: 0.06rem solid #b6b6b6;
      position: relative;

      input {
        width: 18rem;
        height: 2rem;
        outline: none;
        border: none;
        font-size: 0.88rem;
        color: #acacac;
      }

      img {
        cursor: pointer;
        position: absolute;
        right: 1rem;
        top: 0.4rem;
        z-index: 10;
        width: 1.25rem;
        height: 1.25rem;
      }
    }
  }
}
</style>
